package manager.modulo.clientefornecedor.fonte;

import java.sql.SQLException;
import java.util.LinkedList;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import manager.auxiliares.Configurations;
import manager.auxiliares.FocusHelper;
import manager.auxiliares.Format;
import manager.auxiliares.Icons;
import manager.auxiliares.MensagemExcessao;
import manager.auxiliares.WindowsFunctions;
import manager.helpers.validation.FormatedFieldValidator;
import manager.helpers.validation.TextFieldValidator;
import manager.helpers.validation.ValidationFunctions;
import manager.principal.fonte.PainelEndereco;
import manager.principal.fonte.JanelaLogin;
import manager.principal.dao.EnderecoDao;
import manager.modulo.clientefornecedor.dao.EnderecoClienteFornecedorDao;
import manager.modulo.clientefornecedor.dao.PessoaJuridicaDao;
import manager.modulo.clientefornecedor.dao.PessoaFisicaDao;
import manager.modulo.clientefornecedor.dao.ClienteFornecedorDao;
import manager.modulo.clientefornecedor.enumerator.EnumSituacaoClienteFornecedor;
import manager.modulo.clientefornecedor.enumerator.EnumTipoClienteFornecedor.TipoClienteFornecedor;
import manager.modulo.funcionario.enumerator.EnumSexo;

/**
 *
 * @author Thiago
 */
public class JanelaClienteFornecedor extends javax.swing.JFrame {

    int idClienteFornecedor = 0;
    PainelEndereco painelEndereco;

    /**
     * Creates new form UserWindow
     */
    public JanelaClienteFornecedor(int newIdPartner) {
        try {
            // Define layout de acordo com o SO que estiver rodando
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            this.setIconImage(JanelaLogin.icon);
            initComponents();
            idClienteFornecedor = newIdPartner;
            configurarJanela();
            this.setLocationRelativeTo(null);
            this.setVisible(true);

        } catch (Exception e) {
            MensagemExcessao.mostrarMensagem(e, "Usuários");
        }
    }

    private void checkRequiredFields() {
        ((TextFieldValidator) jTextField1).validarCampo();
        ((TextFieldValidator) jTextField3).validarCampo();
        ((TextFieldValidator) jTextField13).validarCampo();

        ((FormatedFieldValidator) jFormattedTextField1).validarCampo();
        ((FormatedFieldValidator) jFormattedTextField2).validarCampo();
        ((FormatedFieldValidator) jFormattedTextField3).validarCampo();
    }

    private LinkedList<String> validateFields() {
        LinkedList<String> fieldList = new LinkedList<String>();


        if (jRadioButton2.isSelected()) {//Pessoa jurídica
            if (!((TextFieldValidator) jTextField3).validarCampo()) {
                fieldList.add(((TextFieldValidator) jTextField3).getjLabel().getText());
            }
            if (!((FormatedFieldValidator) jFormattedTextField3).validarCampo() && jCheckBox2.isSelected()) {
                fieldList.add(((FormatedFieldValidator) jFormattedTextField3).getjLabel().getText());
            }
        } else {
            if (!((TextFieldValidator) jTextField1).validarCampo()) {
                fieldList.add(((TextFieldValidator) jTextField1).getjLabel().getText());
            }
            if (!((FormatedFieldValidator) jFormattedTextField1).validarCampo() && jCheckBox1.isSelected()) {
                fieldList.add(((FormatedFieldValidator) jFormattedTextField1).getjLabel().getText());
            }
            if (!((FormatedFieldValidator) jFormattedTextField2).validarCampo()) {
                fieldList.add(((FormatedFieldValidator) jFormattedTextField2).getjLabel().getText());
            }
        }

        LinkedList<String> listAddress = painelEndereco.validarCampos();
        for (int i = 0; i < listAddress.size(); i++) {
            fieldList.add(listAddress.get(i));
        }

        if (!((TextFieldValidator) jTextField13).validarCampo()) {
            fieldList.add(((TextFieldValidator) jTextField13).getjLabel().getText());
        }


        return fieldList;
    }

    private void adicionarClienteFornecedor() {
        try {
            if (ClienteFornecedorDao.getIdClienteFornecedorPorIdentificador(jTextField13.getText()) == 0) {
                try {
                    JanelaLogin.connection.setAutoCommit(false);

                    ClienteFornecedorDao clienteFornecedorDao = new ClienteFornecedorDao();
                    clienteFornecedorDao.setDataCadastro(Format.getCurrentDatabseTimeStamp());

                    PessoaJuridicaDao pessoaJuridicaDao = new PessoaJuridicaDao();
                    PessoaFisicaDao pessoaFisicaDao = new PessoaFisicaDao();

                    inserirInformacoesEntidades(clienteFornecedorDao, pessoaFisicaDao, pessoaJuridicaDao);

                    clienteFornecedorDao.inserir();

                    if (jRadioButton2.isSelected()) {//Pessoa Jurídica
                        pessoaJuridicaDao.setIdClienteFornecedor(clienteFornecedorDao.getId());
                        pessoaJuridicaDao.inserir();
                    } else {
                        pessoaFisicaDao.setIdClienteFornecedor(clienteFornecedorDao.getId());
                        pessoaFisicaDao.inserir();
                    }

                    if (painelEndereco.estaSelecionado()) {
                        EnderecoDao enderecoDao = painelEndereco.getEndereco();
                        enderecoDao.inserir();

                        EnderecoClienteFornecedorDao enderecoClienteFornecedor = new EnderecoClienteFornecedorDao();
                        enderecoClienteFornecedor.setIdEndereco(enderecoDao.getId());
                        enderecoClienteFornecedor.setIdClienteFornecedor(clienteFornecedorDao.getId());
                        enderecoClienteFornecedor.inserir();
                    }


                    JanelaLogin.connection.commit();

                    JOptionPane.showMessageDialog(null, "Cliente/Fornecedor cadastrado com sucesso.", this.getTitle(), JOptionPane.INFORMATION_MESSAGE);
                    this.dispose();
                } catch (Exception e) {
                    JanelaLogin.connection.rollback();
                    MensagemExcessao.mostrarMensagem(e, "Inserção de Cliente/Fornecedor");
                } finally {
                    JanelaLogin.connection.setAutoCommit(true);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Este identificador já esta cadastrado.", this.getTitle(), JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
            MensagemExcessao.mostrarMensagem(ex, "Inserção de Cliente/Fornecedor");
        }
    }

    private void setEntityInformations() {
        jButton1.setText("Editar");
        jButton1.setIcon(new Icons().getEdit());

        ClienteFornecedorDao clienteFornecedorDao = new ClienteFornecedorDao();
        clienteFornecedorDao.buscar(idClienteFornecedor);

        if (clienteFornecedorDao.getTipo() == TipoClienteFornecedor.PESSOAJURIDICA) {//Pessoa Jurídica
            jRadioButton2.setSelected(true);

            PessoaJuridicaDao corporatePersonDao = new PessoaJuridicaDao();
            corporatePersonDao.buscar(clienteFornecedorDao.getId());

            jTextField3.setText(corporatePersonDao.getNomeFantasia());
            jTextField4.setText(corporatePersonDao.getRazaoSocial());
            if (!corporatePersonDao.getCnpj().equals("")) {
                jCheckBox2.setSelected(true);
                jFormattedTextField3.setText(corporatePersonDao.getCnpj());
                ((FormatedFieldValidator) jFormattedTextField3).validarCampo();
            } else {
                jCheckBox2.setSelected(false);
            }
            jTextField6.setText(corporatePersonDao.getResponsavel());
        } else {// Pessoa Física
            jRadioButton1.setSelected(true);

            PessoaFisicaDao pessoaFisicaDao = new PessoaFisicaDao();
            pessoaFisicaDao.buscar(idClienteFornecedor);

            jTextField1.setText(pessoaFisicaDao.getNome());
            if (!pessoaFisicaDao.getCpf().equals("")) {
                jCheckBox1.setSelected(true);
                jFormattedTextField1.setText(pessoaFisicaDao.getCpf());
                ((FormatedFieldValidator) jFormattedTextField1).validarCampo();
            } else {
                jCheckBox1.setSelected(false);
            }
            jTextField2.setText(pessoaFisicaDao.getIdentidade());
            jFormattedTextField2.setText(Format.formatarTimeStampApresentacao(pessoaFisicaDao.getDtNascimento()));
            jComboBox1.setSelectedItem(EnumSexo.ConvertEnumString(pessoaFisicaDao.getSexo()));
        }

        jTextField7.setText(clienteFornecedorDao.getTelefoneResidencial());
        jTextField8.setText(clienteFornecedorDao.getTelefoneCelular());
        jTextField9.setText(clienteFornecedorDao.getEmail());
        jTextField10.setText(clienteFornecedorDao.getWebsite());
        //jComboBox2.setSelectedItem(ParceiroDao.getSituation(partnerDao.getSituation()));
        jTextField13.setText(clienteFornecedorDao.getIdentificador());
        jTextField11.setText(clienteFornecedorDao.getComplemento());
        jFormattedTextField4.setText(Format.formatarTimeStampApresentacao(clienteFornecedorDao.getDataCadastro()));

        int idAddress = EnderecoClienteFornecedorDao.getIdEnderecoPorClienteFornecedor(clienteFornecedorDao.getId());
        if (idAddress != 0) {
            painelEndereco.carregarInformacoes(idAddress);
        }

    }

    private void editarClienteFornecedor() {
        try {
            int idPartnerSearched = ClienteFornecedorDao.getIdClienteFornecedorPorIdentificador(jTextField13.getText());
            if (idPartnerSearched == 0 || idPartnerSearched == idClienteFornecedor) {
                try {
                    JanelaLogin.connection.setAutoCommit(false);

                    ClienteFornecedorDao clienteFornecedorDao = new ClienteFornecedorDao();
                    clienteFornecedorDao.buscar(idClienteFornecedor);

                    PessoaJuridicaDao pessoaJuridicaDao = new PessoaJuridicaDao(idClienteFornecedor);
                    pessoaJuridicaDao.deletar();
                    PessoaFisicaDao pessoaFisicaDao = new PessoaFisicaDao(idClienteFornecedor);
                    pessoaFisicaDao.deletar();

                    inserirInformacoesEntidades(clienteFornecedorDao, pessoaFisicaDao, pessoaJuridicaDao);

                    clienteFornecedorDao.atualizar();

                    if (jRadioButton2.isSelected()) {//Pessoa Jurídica
                        pessoaJuridicaDao.setIdClienteFornecedor(clienteFornecedorDao.getId());
                        pessoaJuridicaDao.inserir();
                    } else {
                        pessoaFisicaDao.setIdClienteFornecedor(clienteFornecedorDao.getId());
                        pessoaFisicaDao.inserir();
                    }

                    //Removendo endereço antigo
                    int idEndereco = EnderecoClienteFornecedorDao.getIdEnderecoPorClienteFornecedor(idClienteFornecedor);
                    EnderecoClienteFornecedorDao enderecoClienteFornecedor = new EnderecoClienteFornecedorDao(idClienteFornecedor, idEndereco);
                    enderecoClienteFornecedor.deletar();
                    EnderecoDao enderecoDao = new EnderecoDao();
                    enderecoDao.setId(idEndereco);
                    enderecoDao.deletar();



                    if (painelEndereco.estaSelecionado()) {
                        enderecoDao = painelEndereco.getEndereco();
                        enderecoDao.inserir();

                        enderecoClienteFornecedor = new EnderecoClienteFornecedorDao();
                        enderecoClienteFornecedor.setIdEndereco(enderecoDao.getId());
                        enderecoClienteFornecedor.setIdClienteFornecedor(clienteFornecedorDao.getId());
                        enderecoClienteFornecedor.inserir();
                    }

                    JanelaLogin.connection.commit();

                    JOptionPane.showMessageDialog(null, "Cliente/Fornecedor editado com sucesso.", this.getTitle(), JOptionPane.INFORMATION_MESSAGE);
                    this.dispose();
                } catch (Exception e) {
                    JanelaLogin.connection.rollback();
                    MensagemExcessao.mostrarMensagem(e, this.getTitle());
                } finally {
                    JanelaLogin.connection.setAutoCommit(true);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Este identificador já esta cadastrado.", this.getTitle(), JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
            MensagemExcessao.mostrarMensagem(ex, this.getTitle());
        }
    }

    public void inserirInformacoesEntidades(ClienteFornecedorDao clienteFornecedorDao, PessoaFisicaDao pessoaFisicaDao, PessoaJuridicaDao pessoaJuridicaDao) {

        clienteFornecedorDao.setTelefoneCelular(jTextField7.getText());
        clienteFornecedorDao.setTelefoneResidencial(jTextField8.getText());
        clienteFornecedorDao.setEmail(jTextField9.getText());
        clienteFornecedorDao.setWebsite(jTextField10.getText());
        clienteFornecedorDao.setIdentificador(jTextField13.getText());
        clienteFornecedorDao.setSituacao(EnumSituacaoClienteFornecedor.ConvertStringEnum(jComboBox2.getSelectedItem().toString()));
        clienteFornecedorDao.setComplemento(jTextField11.getText());
        clienteFornecedorDao.setTipo((jRadioButton2.isSelected()) ? TipoClienteFornecedor.PESSOAJURIDICA : TipoClienteFornecedor.PESSOAFISICA);

        if (jRadioButton2.isSelected()) {//Pessoa Jurídica
            pessoaJuridicaDao.setNomeFantasia(jTextField3.getText());
            pessoaJuridicaDao.setRazaoSocial(jTextField4.getText());
            pessoaJuridicaDao.setCnpj((jCheckBox2.isSelected()) ? Format.formatCnpjToDatabase(jFormattedTextField3.getText()) : "");
            pessoaJuridicaDao.setResponsavel(jTextField6.getText());
        } else { //Pessoa Física
            pessoaFisicaDao.setNome(jTextField1.getText());
            pessoaFisicaDao.setCpf((jCheckBox1.isSelected()) ? Format.formatCpfToDatabase(jFormattedTextField1.getText()) : "");
            pessoaFisicaDao.setIdentidade(jTextField2.getText());
            pessoaFisicaDao.setDtNascimento(Format.formatVisualDateToTimestamp(jFormattedTextField2.getText()));
            pessoaFisicaDao.setSexo(EnumSexo.ConvertStringEnum(jComboBox1.getSelectedItem().toString()));
        }
    }

    /**
     * Inicializando as configurações da tela
     *
     * @throws SQLException
     */
    private void configurarJanela() throws SQLException {
        painelEndereco = new PainelEndereco();
        jPanel4.add(painelEndereco);
        painelEndereco.setBounds(60, 145, 620, 181);

        LinkedList<String> listaSituacoes = EnumSituacaoClienteFornecedor.ListaStringSituacoes();
        for (int i = 0; i < listaSituacoes.size(); i++) {
            jComboBox2.addItem(listaSituacoes.get(i));
        }

        LinkedList<String> listaSexo = EnumSexo.ListaStringSexo();
        for (int i = 0; i < listaSexo.size(); i++) {
            jComboBox1.addItem(listaSexo.get(i));
        }

        if (idClienteFornecedor != 0) { // Edição de usuário
            setEntityInformations();
        } else {
            jFormattedTextField4.setText(Format.getCurrentVisualDate());
            this.checkRequiredFields();
        }
        if (jTextField1.isVisible()) {
            jTextField1.requestFocus();
        } else {
            jTextField3.requestFocus();
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton1 = new javax.swing.JRadioButton();
        jPanel4 = new javax.swing.JPanel();
        jButton6 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField1 = new TextFieldValidator(60, -1, true, true, "text", jLabel1);
        jFormattedTextField1 = new FormatedFieldValidator(false, true, "cpf", jLabel2);
        jTextField2 = new TextFieldValidator(20, -1, false, true, "text", jLabel3);
        jFormattedTextField2 = new FormatedFieldValidator(true, true, "date", jLabel5);
        jComboBox1 = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jPanel6 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextField3 = new TextFieldValidator(80, -1, true, true, "text", jLabel6);
        jTextField4 = new TextFieldValidator(80, -1, false, true, "text", jLabel7);
        jTextField6 = new TextFieldValidator(80, -1, false, true, "text", jLabel9);
        jCheckBox2 = new javax.swing.JCheckBox();
        jFormattedTextField3 = new FormatedFieldValidator(false, true, "cnpj", jLabel8);
        jPanel7 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jTextField7 = new TextFieldValidator(11, -1, false, true, "text", jLabel10);
        jTextField8 = new TextFieldValidator(11, -1, false, true, "text", jLabel11);
        jTextField9 = new TextFieldValidator(80, -1, false, true, "email", jLabel12);
        jTextField10 = new TextFieldValidator(80, -1, false, true, "text", jLabel13);
        jComboBox2 = new javax.swing.JComboBox();
        jTextField11 = new TextFieldValidator(200, -1, false, true, "text", jLabel15);
        jTextField13 = new TextFieldValidator(80, -1, true, true, "text", jLabel17);
        jFormattedTextField4 = new FormatedFieldValidator(false, false, "date", jLabel16);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Parceiros");
        setBackground(Configurations.getBackGroundColor());
        setMinimumSize(new java.awt.Dimension(620, 390));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jPanel3.setBackground(Configurations.getBackGroundColor());
        jPanel3.setPreferredSize(new java.awt.Dimension(700, 320));
        jPanel3.setLayout(null);

        jPanel1.setBackground(Configurations.getBackGroundColor());
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel1.setLayout(null);

        jPanel2.setBackground(Configurations.getBackGroundColor());
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo de Cliente/Fornecedor"));
        jPanel2.setForeground(Configurations.getBackGroundColor());
        jPanel2.setLayout(null);

        jRadioButton2.setBackground(Configurations.getBackGroundColor());
        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jRadioButton2.setSelected(true);
        jRadioButton2.setText("Pessoa Jurídica");
        jRadioButton2.setFocusable(false);
        jRadioButton2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jRadioButton2StateChanged(evt);
            }
        });
        jPanel2.add(jRadioButton2);
        jRadioButton2.setBounds(170, 20, 140, 23);

        jRadioButton1.setBackground(Configurations.getBackGroundColor());
        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jRadioButton1.setText("Pessoa Física");
        jRadioButton1.setFocusable(false);
        jPanel2.add(jRadioButton1);
        jRadioButton1.setBounds(320, 20, 120, 23);

        jPanel1.add(jPanel2);
        jPanel2.setBounds(0, 0, 620, 60);

        jPanel4.setBackground(Configurations.getBackGroundColor());
        jPanel4.setLayout(null);

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/cancel.png"))); // NOI18N
        jButton6.setText("Cancelar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel4.add(jButton6);
        jButton6.setBounds(120, 300, 100, 23);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/add.png"))); // NOI18N
        jButton1.setText("Cadastrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel4.add(jButton1);
        jButton1.setBounds(10, 300, 100, 23);

        jPanel5.setBackground(Configurations.getBackGroundColor());
        jPanel5.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Nome");
        jPanel5.add(jLabel1);
        jLabel1.setBounds(10, 10, 70, 14);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("CPF");
        jPanel5.add(jLabel2);
        jLabel2.setBounds(295, 10, 60, 14);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Identidade");
        jPanel5.add(jLabel3);
        jLabel3.setBounds(370, 10, 70, 14);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Nascimento");
        jPanel5.add(jLabel5);
        jLabel5.setBounds(455, 10, 70, 14);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Sexo");
        jPanel5.add(jLabel4);
        jLabel4.setBounds(530, 10, 34, 14);
        jPanel5.add(jTextField1);
        jTextField1.setBounds(10, 30, 260, 20);

        jFormattedTextField1.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jFormattedTextField1.setEnabled(false);
        jPanel5.add(jFormattedTextField1);
        jFormattedTextField1.setBounds(275, 30, 90, 20);
        jPanel5.add(jTextField2);
        jTextField2.setBounds(370, 30, 80, 20);
        jPanel5.add(jFormattedTextField2);
        jFormattedTextField2.setBounds(455, 30, 70, 20);

        jPanel5.add(jComboBox1);
        jComboBox1.setBounds(530, 30, 80, 20);

        jCheckBox1.setBackground(Configurations.getBackGroundColor());
        jCheckBox1.setFocusable(false);
        jCheckBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCheckBox1ItemStateChanged(evt);
            }
        });
        jPanel5.add(jCheckBox1);
        jCheckBox1.setBounds(271, 10, 20, 15);

        jPanel4.add(jPanel5);
        jPanel5.setBounds(0, 0, 620, 50);
        jPanel5.setVisible(false);

        jPanel6.setBackground(Configurations.getBackGroundColor());
        jPanel6.setLayout(null);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Nome Fantasia");
        jPanel6.add(jLabel6);
        jLabel6.setBounds(10, 10, 110, 14);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("Razão Social");
        jPanel6.add(jLabel7);
        jLabel7.setBounds(180, 10, 90, 14);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("CNPJ");
        jPanel6.add(jLabel8);
        jLabel8.setBounds(352, 10, 50, 14);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setText("Responsável");
        jPanel6.add(jLabel9);
        jLabel9.setBounds(450, 10, 110, 14);
        jPanel6.add(jTextField3);
        jTextField3.setBounds(10, 30, 165, 20);
        jPanel6.add(jTextField4);
        jTextField4.setBounds(180, 30, 150, 20);
        jPanel6.add(jTextField6);
        jTextField6.setBounds(450, 30, 160, 20);

        jCheckBox2.setBackground(Configurations.getBackGroundColor());
        jCheckBox2.setFocusable(false);
        jCheckBox2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCheckBox2ItemStateChanged(evt);
            }
        });
        jPanel6.add(jCheckBox2);
        jCheckBox2.setBounds(331, 10, 20, 15);

        jFormattedTextField3.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jFormattedTextField3.setEnabled(false);
        jPanel6.add(jFormattedTextField3);
        jFormattedTextField3.setBounds(335, 30, 110, 20);

        jPanel4.add(jPanel6);
        jPanel6.setBounds(0, 50, 620, 50);
        jPanel6.setBounds(0, 0, 620, 50);

        jPanel7.setBackground(Configurations.getBackGroundColor());
        jPanel7.setLayout(null);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setText("Telefone");
        jPanel7.add(jLabel10);
        jLabel10.setBounds(10, 10, 70, 14);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel11.setText("Celular");
        jPanel7.add(jLabel11);
        jLabel11.setBounds(105, 10, 60, 14);

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Email");
        jPanel7.add(jLabel12);
        jLabel12.setBounds(200, 10, 70, 14);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel13.setText("Website");
        jPanel7.add(jLabel13);
        jLabel13.setBounds(375, 10, 70, 14);

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel14.setText("Situação");
        jPanel7.add(jLabel14);
        jLabel14.setBounds(530, 10, 60, 14);

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel15.setText("Informações adicionais");
        jPanel7.add(jLabel15);
        jLabel15.setBounds(215, 55, 150, 14);

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel16.setText("Cadastro");
        jPanel7.add(jLabel16);
        jLabel16.setBounds(530, 55, 70, 14);

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel17.setText("Identificador");
        jPanel7.add(jLabel17);
        jLabel17.setBounds(10, 55, 120, 14);
        jPanel7.add(jTextField7);
        jTextField7.setBounds(10, 30, 90, 20);

        jTextField8.setToolTipText("Celular");
        jPanel7.add(jTextField8);
        jTextField8.setBounds(105, 30, 90, 20);
        jPanel7.add(jTextField9);
        jTextField9.setBounds(200, 30, 170, 20);
        jPanel7.add(jTextField10);
        jTextField10.setBounds(375, 30, 150, 20);
        jPanel7.add(jComboBox2);
        jComboBox2.setBounds(530, 30, 80, 20);
        jPanel7.add(jTextField11);
        jTextField11.setBounds(215, 75, 310, 20);
        jPanel7.add(jTextField13);
        jTextField13.setBounds(10, 75, 200, 20);

        jFormattedTextField4.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jFormattedTextField4.setEnabled(false);
        jPanel7.add(jFormattedTextField4);
        jFormattedTextField4.setBounds(530, 75, 80, 20);

        jPanel4.add(jPanel7);
        jPanel7.setBounds(0, 99, 610, 95);
        jPanel7.setBounds(0, 50, 610, 95);

        jPanel1.add(jPanel4);
        jPanel4.setBounds(0, 60, 620, 330);

        jPanel3.add(jPanel1);
        jPanel1.setBounds(0, 0, 620, 390);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        WindowsFunctions.resizePanel(jPanel3, jPanel1);
    }//GEN-LAST:event_formComponentResized

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        LinkedList<String> fieldValidadeList = validateFields();
        if (fieldValidadeList.size() == 0) {
            if (idClienteFornecedor == 0) {
                adicionarClienteFornecedor();
            } else {
                editarClienteFornecedor();
            }
        } else {
            JOptionPane.showMessageDialog(null, ValidationFunctions.getValidationMessage(fieldValidadeList), this.getTitle(), JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jRadioButton2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jRadioButton2StateChanged
        if (jRadioButton2.isSelected()) {
            jPanel6.setVisible(true);
            jTextField3.requestFocus();
            jPanel5.setVisible(false);
        } else {
            jPanel5.setVisible(true);
            jTextField1.requestFocus();
            jPanel6.setVisible(false);
        }
    }//GEN-LAST:event_jRadioButton2StateChanged

    private void jCheckBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox1ItemStateChanged
        FormatedFieldValidator formatedFieldValidator = ((FormatedFieldValidator) jFormattedTextField1);
        if (jCheckBox1.isSelected()) {
            formatedFieldValidator.setIsRequired(true);
            formatedFieldValidator.setEnabled(true);
            formatedFieldValidator.requestFocus();
            formatedFieldValidator.setToolTipText(formatedFieldValidator.getToolTip());
            formatedFieldValidator.validarCampo();
        } else {
            formatedFieldValidator.setIsRequired(false);
            formatedFieldValidator.setText("");
            formatedFieldValidator.requestFocus();
            FocusHelper.goToNextFocus();
            formatedFieldValidator.setEnabled(false);
            formatedFieldValidator.setToolTipText(formatedFieldValidator.getToolTip());
            formatedFieldValidator.validarCampo();
        }
    }//GEN-LAST:event_jCheckBox1ItemStateChanged

    private void jCheckBox2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox2ItemStateChanged
        FormatedFieldValidator formatedFieldValidator = ((FormatedFieldValidator) jFormattedTextField3);
        if (jCheckBox2.isSelected()) {
            formatedFieldValidator.setIsRequired(true);
            formatedFieldValidator.setEnabled(true);
            formatedFieldValidator.requestFocus();
            formatedFieldValidator.setToolTipText(formatedFieldValidator.getToolTip());
            formatedFieldValidator.validarCampo();
        } else {
            formatedFieldValidator.setIsRequired(false);
            formatedFieldValidator.setText("");
            formatedFieldValidator.requestFocus();
            FocusHelper.goToNextFocus();
            formatedFieldValidator.setEnabled(false);
            formatedFieldValidator.setToolTipText(formatedFieldValidator.getToolTip());
            formatedFieldValidator.validarCampo();
        }
    }//GEN-LAST:event_jCheckBox2ItemStateChanged
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton6;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JFormattedTextField jFormattedTextField2;
    private javax.swing.JFormattedTextField jFormattedTextField3;
    private javax.swing.JFormattedTextField jFormattedTextField4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField13;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    // End of variables declaration//GEN-END:variables
}
